<%--
  Created by IntelliJ IDEA.
  User: lijincheng
  Date: 2020/7/11
  Time: 1:41 下午
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>系统登录 - 超市订单管理系统</title>
    <link type="text/css" rel="stylesheet" href="/statics/css/style.css"/>
    <script type="text/javascript" src="/statics/js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
        /* if(top.location!=self.location){
              top.location=self.location;
         } */
    </script>
</head>
<body class="login_bg">
<section class="loginBox">
    <header class="loginHeader">
        <h1>超市订单管理系统</h1>
    </header>
    <section class="loginCont">
        <form class="loginForm" name="actionForm" id="actionForm" method="post">
            <div class="info"></div>
            <div class="inputbox">
                <label for="userCode">用户名：</label>
                <input type="text" class="input-text" id="userCode" name="userCode" placeholder="请输入用户名" required/>
            </div>
            <div class="inputbox">
                <label for="userPassword">密码：</label>
                <input type="password" id="userPassword" name="userPassword" placeholder="请输入密码" required/>
            </div>
            <div class="inputbox">
                <label for="code">验证码：</label>
                <input type="text" name="code" id="code" onfocus="" style="width: 100px">
                <img id="imgVerify" src="" width="100px" height="30px" alt="点击更换验证码" onclick="getVerify()"/>
            </div>
            <div class="subBtn">
                <input type="button" onclick="login()" value="登录"/>
                <input type="reset" value="重置"/>
            </div>
        </form>
    </section>
</section>
<script>
    $(document.body).ready(function () {
        $("#imgVerify").attr("src", "/user/getVerify?" + Math.random());
    });

    function getVerify() {
        var src1 = document.getElementById('imgVerify');
        src1.src = "/user/getVerify?" + Math.random();
    }
    function login() {
        $.ajax({
            async: true,
            type: "POST",
            data: {"name": $("#userCode").val(), "pass": $("#userPassword").val(),"code":$("#code").val()},
            url: "/user/doLogin",
            success: function (data) {
                console.log(data);
                if (data=="success"){
                    window.location.href="/user/main";
                }else if(data=="code"){
                    alert("验证码错误");
                }else {
                    alert("用户名或密码错误");
                }
            }
        });
    }
</script>
</body>
</html>
